package com.example.administrator.myproject.home

import android.support.v4.app.FragmentActivity
import android.support.v7.widget.RecyclerView
import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.ImageView
import android.widget.TextView

import com.example.administrator.myproject.R
import com.example.administrator.myproject.bean.CartModel
import com.example.administrator.myproject.bean.Collect

class CartAdapter(private val mContext: FragmentActivity?) : RecyclerView.Adapter<CartAdapter.Holder>() {
    private var lists: List<CartModel>? = null
    private val inflater: LayoutInflater

    override fun onCreateViewHolder(viewGroup: ViewGroup, i: Int): Holder {
        val view = inflater.inflate(R.layout.cart_buttom, viewGroup, false)
        return Holder(view)
    }

    override fun onBindViewHolder(holder: Holder, i: Int) {

        holder.tv1.text = lists!![i].getName()
        holder.tv2.text = "" + lists!![i].getPrice()
        println(lists!![i].getCount())
        holder.tv3.text = "" +lists!![i].getCount()
        holder.tv4.text = "" + (lists!![i].getPrice()!! * lists!![i].getCount())


    }

    override fun getItemCount(): Int {
        return if (lists == null) 0 else lists!!.size
    }

    fun setData(list: List<CartModel>) {
        this.lists = list
        notifyDataSetChanged()
    }

    inner class Holder(itemView: View) : RecyclerView.ViewHolder(itemView) {
        val tv1: TextView
        val tv2: TextView
        val tv3: TextView
        val tv4: TextView

        init {
            println("!!!")

            tv1 = itemView.findViewById(R.id.tv1)
            tv2 = itemView.findViewById(R.id.tv2)
            tv3 = itemView.findViewById(R.id.tv3)
            tv4 = itemView.findViewById(R.id.tv4)
            println("!!!")
        }
    }

    init {
        this.inflater = LayoutInflater.from(mContext)
    }
}
